#pragma once
#include<iostream>
#include<memory>
#include<string>
#include<functional>
#include"Internet.hpp"

using func_t =std:: function<void()>;
class EpollServer;
class Connection
{
    public:
    Connection(int sockfd)
    :_sockfd(sockfd)
    ,_events(0)
    {

    }
    void Init(func_t receiver,func_t sender,func_t excepter)
    {
        _receiver = receiver;
        _sender = sender;
        _excepter = excepter; 
    }
    void SetPeer(const InetAddr& peer_addr)
    {
            _peer_addr = peer_addr;
    }
    int SockfdVal()
    {
        return _sockfd;
    }
    uint32_t GetEvents()
    {
        return _events;
    }
    void SetEvents(int events)
    {
        _events = events;
    }
    void CallRev()
    {
        if(_receiver != nullptr)
        _receiver();
    }
    void CallSend()
    {
        if(_sender!= nullptr)
        _sender;
         
    }
    void Excepter()
    {
        if(_excepter  != nullptr)
        {
            _excepter;
        }
    }
    ~Connection()
    {

    }


    private:
    int _sockfd;
    std::string _inbuffer;
    std::string _outbuffer;
    InetAddr _peer_addr;

    func_t _receiver;
    func_t _sender;
    func_t _excepter;

    EpollServer* _pollself;

    uint32_t _events;
};